package com.shao.utils;

import org.apache.commons.beanutils.BeanUtils;

import java.lang.reflect.InvocationTargetException;
import java.util.Map;

/**
 * Created with IntelliJ IDEA.
 * User: SJP
 * Date: 2021/5/16
 * Time: 20:45
 * Description: No Description
 */
public class WebUtils {
    /**
     * 将需要请求参数即map的value值注入对应的javaBean属性中，依赖于Javabean的set方法
     * @param bean
     * @param value
     * @param <T>
     * @return
     */
    public static<T> T copyParaToBean(T bean, Map value) {
        try {
            BeanUtils.populate(bean, value);
        } catch (Exception e) {
           // e.printStackTrace();
        }
        return bean;
    }

    /**
     * 將字符串轉化為整型int数据
     * @param str
     * @param defaultValue
     * @return
     */
    public static int parseInt(String str,int defaultValue){
        try {
            return Integer.parseInt(str);
        } catch (Exception e) {
           // e.printStackTrace();
        }
        return defaultValue;
    }
}
